import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;


public class NodeQuestLog {/*
	
	Player player;
	ArrayList<Integer> listWithQuestIndexs = new ArrayList<Integer>();
	protected int currentQuestLogLevel = 0;
	protected int finalQuestLogLevel = 0;
	String[][] QuestLogLevels = new String[20][6];
	final int ENLARGE_VALUE = 100;
	InterfaceFrame frame;
	JComponent lastButton;
	CustomButton quest1 = new CustomButton();
	CustomButton quest2 = new CustomButton();
	CustomButton quest3 = new CustomButton();
	CustomButton quest4 = new CustomButton();
	CustomButton quest5 = new CustomButton();
	CustomButton quest6 = new CustomButton();
	CustomArrowButton up = new CustomArrowButton("Up");
	CustomArrowButton down = new CustomArrowButton("Down");
	
	
	NodeQuestLog(Player player, InterfaceFrame frame){
		
		listWithQuestIndexs = player.activeQuests;
		this.player = player;
		this.frame = frame;
		createQuestLogLevels();
		up.addActionListener(new QuestListener());
		down.addActionListener(new QuestListener());
		quest1.addActionListener(new QuestListener());
		quest2.addActionListener(new QuestListener());
		quest3.addActionListener(new QuestListener());
		quest4.addActionListener(new QuestListener());
		quest5.addActionListener(new QuestListener());
		quest6.addActionListener(new QuestListener());
		quest1.addMouseListener(new TheMouseListener());
		quest2.addMouseListener(new TheMouseListener());
		quest3.addMouseListener(new TheMouseListener());
		quest4.addMouseListener(new TheMouseListener());
		quest5.addMouseListener(new TheMouseListener());
		quest6.addMouseListener(new TheMouseListener());
		up.addMouseListener(new TheMouseListener());
		down.addMouseListener(new TheMouseListener());
		
	}
	
	public void showQuestLogLevel(int level){
		
		createQuestLogLevels();
		frame.nface.popOptions.setLayout(new FlowLayout(FlowLayout.LEFT,0,0));
		frame.nface.imageLabel.setIcon(new ImageIcon(getClass().getResource(frame.map.allQuests.get(listWithQuestIndexs.get(0)).questPic)));
		
		if(QuestLogLevels[level][0] != null)
			quest1.setText(QuestLogLevels[level][0]);
		if(QuestLogLevels[level][1] != null)
			quest2.setText(QuestLogLevels[level][1]);
		if(QuestLogLevels[level][2] != null)
			quest3.setText(QuestLogLevels[level][2]);
		if(QuestLogLevels[level][3] != null)
			quest4.setText(QuestLogLevels[level][3]);
		if(QuestLogLevels[level][4] != null)
			quest5.setText(QuestLogLevels[level][4]);
		if(QuestLogLevels[level][5] != null)
			quest6.setText(QuestLogLevels[level][5]);
		
		
		if(QuestLogLevels[level][0] != null)
			frame.nface.popOptions.add(quest1);
		else
			frame.nface.popOptions.remove(quest1);
		if(QuestLogLevels[level][1] != null)
			frame.nface.popOptions.add(quest2);
		else
			frame.nface.popOptions.remove(quest2);
		if(QuestLogLevels[level][2] != null)
			frame.nface.popOptions.add(quest3);
		else
			frame.nface.popOptions.remove(quest3);
		if(QuestLogLevels[level][3] != null)
			frame.nface.popOptions.add(quest4);
		else
			frame.nface.popOptions.remove(quest4);
		if(QuestLogLevels[level][4] != null)
			frame.nface.popOptions.add(quest5);
		else
			frame.nface.popOptions.remove(quest5);
		if(QuestLogLevels[level][5] != null)
			frame.nface.popOptions.add(quest6);
		else
			frame.nface.popOptions.remove(quest6);
		
		if(currentQuestLogLevel != finalQuestLogLevel && listWithQuestIndexs.size() > 6)
			frame.nface.popOptions.add(down);
		else
			frame.nface.popOptions.remove(down);
		if(currentQuestLogLevel != 0)
			frame.nface.popOptions.add(up);
		else
			frame.nface.popOptions.remove(up);
	}
	
	//Skapar en större array, behövs då vi inte vet hur många quests spelaren har.
    private void enlarge(){
    	
    	int newLength = 1 + QuestLogLevels.length + ENLARGE_VALUE * QuestLogLevels.length/100;
    	String[][] newArray = new String[newLength][6];
    	
    	for(int index = 0; index < QuestLogLevels.length; index++){
    		for(int j = 0; j < 6; j++)
    			newArray[index][j] = QuestLogLevels[index][j];
    	}
    	
    	QuestLogLevels = newArray;
    	
    }
    
    public void createQuestLogLevels(){
    	
    	QuestLogLevels = new String[20][6];
    	listWithQuestIndexs = player.activeQuests;
    	
    	//Undersöker vilken sista Leveln är.
    	if(listWithQuestIndexs.size()%6 == 0)
    		finalQuestLogLevel = listWithQuestIndexs.size()/6 - 1;
    	else
    		finalQuestLogLevel = listWithQuestIndexs.size()/6;
    	
    	String level[] = new String[6];
    	int index = 0;
    	
    	for(int i = 0; i <= finalQuestLogLevel; i++){
    		
    		//Om QuestLogLevels arrayen är full, skapa en större!
    		if(QuestLogLevels.length <= index)
    			enlarge();
    		
    		//Lopar fram en sträng till varje index som innehåller hur många quests och namnet.
    		for(int j = 0; j < 6; j++){
    			level[i] = frame.map.allQuests.get(listWithQuestIndexs.get(index)).questName;
    			QuestLogLevels[i][j] = level[i];
    			index++;
    			
    			//Ifall vi kommit till slutet bryt.
    			if(index >= listWithQuestIndexs.size()){
    				break;
    			}
    			
    		}
    		
    	}
    	
    }
    
	
	private class QuestListener implements ActionListener{

		@Override
		public void actionPerformed(ActionEvent e) {
			if(e.getSource().equals(down)){
				
				if(lastButton != null)
					lastButton.setForeground(Color.BLACK);
				lastButton = down;
				down.setForeground(Color.BLUE);
				currentQuestLogLevel++;
				showQuestLogLevel(currentQuestLogLevel);
			}
			else if(e.getSource().equals(up)){

				if(lastButton != null)
					lastButton.setForeground(Color.BLACK);
				lastButton = up;
				up.setForeground(Color.BLUE);
				currentQuestLogLevel--;
				showQuestLogLevel(currentQuestLogLevel);
			}

			else if(e.getSource().equals(quest1)){
				if(lastButton != null)
					lastButton.setForeground(Color.BLACK);
				lastButton = quest1;
				quest1.setForeground(Color.BLUE);
				int index = currentQuestLogLevel * 6;
				frame.nface.imageLabel.setIcon(new ImageIcon(getClass().getResource(frame.map.allQuests.get(listWithQuestIndexs.get(index)).questPic)));
				frame.nface.textArea.setText(frame.map.allQuests.get(listWithQuestIndexs.get(index)).dialog);
			}
			else if(e.getSource().equals(quest2)){
				if(lastButton != null)
					lastButton.setForeground(Color.BLACK);
				lastButton = quest2;
				quest2.setForeground(Color.BLUE);
				int index = currentQuestLogLevel * 6 + 1;
				frame.nface.imageLabel.setIcon(new ImageIcon(getClass().getResource(frame.map.allQuests.get(listWithQuestIndexs.get(index)).questPic)));
				frame.nface.textArea.setText(frame.map.allQuests.get(listWithQuestIndexs.get(index)).dialog);
			}
			else if(e.getSource().equals(quest3)){
				if(lastButton != null)
					lastButton.setForeground(Color.BLACK);
				lastButton = quest3;
				quest3.setForeground(Color.BLUE);
				int index = currentQuestLogLevel * 6 + 2;
				frame.nface.imageLabel.setIcon(new ImageIcon(getClass().getResource(frame.map.allQuests.get(listWithQuestIndexs.get(index)).questPic)));
				frame.nface.textArea.setText(frame.map.allQuests.get(listWithQuestIndexs.get(index)).dialog);
			}
			else if(e.getSource().equals(quest4)){
				if(lastButton != null)
					lastButton.setForeground(Color.BLACK);
				lastButton = quest4;
				quest4.setForeground(Color.BLUE);
				int index = currentQuestLogLevel * 6 + 3;
				frame.nface.imageLabel.setIcon(new ImageIcon(getClass().getResource(frame.map.allQuests.get(listWithQuestIndexs.get(index)).questPic)));
				frame.nface.textArea.setText(frame.map.allQuests.get(listWithQuestIndexs.get(index)).dialog);
			}
			else if(e.getSource().equals(quest5)){
				if(lastButton != null)
					lastButton.setForeground(Color.BLACK);
				lastButton = quest5;
				quest5.setForeground(Color.BLUE);
				int index = currentQuestLogLevel * 6 + 4;
				frame.nface.imageLabel.setIcon(new ImageIcon(getClass().getResource(frame.map.allQuests.get(listWithQuestIndexs.get(index)).questPic)));
				frame.nface.textArea.setText(frame.map.allQuests.get(listWithQuestIndexs.get(index)).dialog);
			}
			else if(e.getSource().equals(quest6)){
				if(lastButton != null)
					lastButton.setForeground(Color.BLACK);
				lastButton = quest6;
				quest6.setForeground(Color.BLUE);
				int index = currentQuestLogLevel * 6 + 5;
				frame.nface.imageLabel.setIcon(new ImageIcon(getClass().getResource(frame.map.allQuests.get(listWithQuestIndexs.get(index)).questPic)));
				frame.nface.textArea.setText(frame.map.allQuests.get(listWithQuestIndexs.get(index)).dialog);
			}
			
			frame.getContentPane().repaint();
		}
		
	}
	
	private class CustomButton extends JButton{
		
		private static final long serialVersionUID = 1L;
		

		CustomButton(){
			this.setContentAreaFilled(false);
			this.setForeground(Color.BLACK);
		}
		
		@Override
		public Dimension getMinimumSize(){
			return new Dimension(306,50);	
		}
		@Override
		public Dimension getMaximumSize(){
			return new Dimension(306,50);	
		}
		@Override
		public Dimension getPreferredSize(){
			return new Dimension(306,50);	
		}
		
	}
	
	private class CustomArrowButton extends JButton{
		
		private static final long serialVersionUID = 1L;
		CustomArrowButton(String str){

			this.setContentAreaFilled(false);
			this.setForeground(Color.BLACK);
			setText(str);
		}
		
		@Override
		public Dimension getMinimumSize(){
			return new Dimension(153,50);	
		}
		@Override
		public Dimension getMaximumSize(){
			return new Dimension(153,50);	
		}
		@Override
		public Dimension getPreferredSize(){
			return new Dimension(153,50);	
		}
		
	}
	
	private class TheMouseListener implements MouseListener{

		@Override
		public void mouseClicked(MouseEvent e){
		}

		@Override
		public void mouseEntered(MouseEvent e) {
		}

		@Override
		public void mouseExited(MouseEvent e) {
		}
		
		@Override
		public void mousePressed(MouseEvent e) {
			frame.nface.popPrime.show(frame, 50, 55);
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			
		}
		
	}*/
	
}
